<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<meta name="author" content="liunan">
	<title>审核申请</title>
	<script type="text/javascript">
	var org = Common.cOrg();					//当前单位	
	var qt = {};								//数据表格对象
	var qt1 = {};
	var qt2 = {};
	var inited = false;							//初始化标志	
	var ids ={};								//全局变量ＩＤ
	var initable = false;	
	var detail_editable =false;						//修改或显示明细
	function load(){
		Eui.showNavigation();
		setPages(["listview","listview1","information","information1","information2"]);
		//初始化
	
		Common.initDict(searchForm.status,
						Common.getSubsetItems("cardbill_status",[Constants.CARDBILL_STATUS_REQUEST,
																Constants.CARDBILL_STATUS_PASSED,
																Constants.CARDBILL_STATUS_REJECTED]),
						"全 部"
		);
		DWR.call("storeQueryService.getRequestOrgs",function(result){
				Common.initDict(searchForm.requestCorp,result,"全 部","id","name");	
			})
		
		searchForm.organization.value = org.id;
		Eui.initBeginDateInput("beginDateTd","起始日期","searchForm","applyTime","invalidTime","_pastDate");
		Eui.initEndDateInput("endDateTd","结束日期","searchForm","applyTime","invalidTime","_pastDate");
		createTable();
	}
	//页面刷新查询
	function checkQuery(){
		if(!checkForm(searchForm))return;
		qt.showTable();
	}	
	//申请单列表	
	function createTable(){
		var columns = []
		columns[0] = {render:number};
		columns[8] = {title:"操作",width:"10%",render:handle,align:"center",order:false};
		
		qt = new QueryTable("user_task_query","searchForm","datalist",columns);
	}	
	function number(v,r){
		return "<a href=# onclick=\"onEdit('"+r[0]+"');\">"+v+"</a>";		
	}
	//根据状态使用对应操作
	function handle(v,r){
		if(r[8]==Constants.CARDBILL_STATUS_PASSED){
			return "<div style='color:gray'>批准 <a href=# onclick=\"onEdit1('"+r[0]+"');return false;\">拒绝</a></div>"
		}else if(r[8]==Constants.CARDBILL_STATUS_REJECTED){
			return "<div style='color:gray'><a href=# onclick=\"onEdit2('"+r[0]+"');return false;\">批准</a> 拒绝</div>"
		}else if(r[8]==Constants.CARDBILL_STATUS_REQUEST){
			return "<a href=# onclick=\"onEdit2('"+r[0]+"');return false;\">批准</a> <a href=# onclick=\"onEdit1('"+r[0]+"');return false;\">拒绝</a>"
		}else{
			return "<div style='color:gray'>批准 拒绝</div>"
		} 
	}
//----------------------------
	var request = 0;       //用于单据是否被合并
	var orderId;
	//根据类型调用相应的查询方法
	function onEdit(id){
		if (id != null){
			orderId=id
			requestframe.document.location.href = "request_order_detail.html";
			switchPage("listview1")
		}
	}
	
	//页面刷新返回
	function backShow(){
		switchPage('listview')
		qt.showTable();
	}
	
	//拒绝页面付值
	function onEdit1(id){
		ids=id;
		$("information_page1").description.value = "";
		DWR.call("cardRequestService.getRequestOrder",id,function(app){
			var cardBill=app.order;
			cardBill.cardType = app.cardType.name;
			cardBill.status = Common.getText("cardbill_status",cardBill.status);
			cardBill.location = app.location.name;
			if(cardBill.createTime)
				cardBill.createTime = Format.formatToMM(cardBill.createTime);
			Common.showDetail("information_page1",cardBill);
		});
		switchPage("information1");
	}
	//退库操作页面付值
	function onEdit2(id){
		ids=id;
		DWR.call("cardRequestService.getRequestOrder",id,function(app){
			var cardBill=app.order;
			cardBill.location = app.location.name;
			cardBill.cardType = app.cardType.name;
			if(cardBill.createTime)
				cardBill.createTime = Format.formatToMM(cardBill.createTime);
			cardBill.status = Common.getText("cardbill_status",cardBill.status);
			Common.showDetail("information_page2",cardBill);
		});
		switchPage("information2");
	}
	//改变为批准状态
	function affirm(){
		if(showQuestion("请确认是否批准?")){
			DWR.call("cardRequestService.verifyCardReqOrder",ids,function(){
				showInformation("批准成功");
				switchPage("listview");
				qt.showTable();
			});
		}	
	}
	//改变为拒绝状态
	function validate(){
		if(!checkForm("information_page1"))return;
		if(showQuestion("请确认是否拒绝?")){
			var rejectReason = $("information_page1").description.value;
			DWR.call("cardRequestService.rejectCardReqOrder",ids,rejectReason,function(){
				showInformation("拒绝成功");
				switchPage("listview");
				qt.showTable();
			});
		}
	}
	function selCardType(){
		var v = openDialogFrame("/basic/card_type_list.html?",'请选择卡片类型',464,700);
		searchForm.cardType.value=v[1];
	}
	function backShow1(){
		switchPage('listview')
	}
</script>
</head>

<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="content">
	<!--查询静态页面部分-->
	<div id="listview">	
		<!--查询条件form-->
		<div class="searchForm">
			<form id="searchForm" name="searchForm">
				<input type="hidden" name="organization" />
				<input type="hidden" name="orderType" />
				<input type="hidden" name="beinStatus" value=101 />
				<input type="hidden" name="endStatus" value=103 />
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="label4">
					<tr>
						<td><label>单据编号</label> <input type="text" name="serialID" onblur="checkV(this,'int')"></td>
						<td><label>申请方</label> <select name="requestCorp"></select></td>
						<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <select name="status"><option></option></select></td>
					</tr><tr>	
						<td id="beginDateTd"></td>
						<td id="endDateTd"></td>
						<td><label>卡片类型</label> <input type="text" name="cardType"><a class=orga title="选择卡片规格" href="javascript:void(0)" onclick="selCardType()">&nbsp;&nbsp;</a></td>
						<td><button type="button" onclick="checkQuery()">查 询</button></td>
					</tr>
				</table>
			</form>
		</div>
		<div id=datalist></div>
	</div>
	<!--单详细信息页面-->
	<div class="listview1" id="listview1" style='display:none;'>
		<iframe id="requestframe" name="requestframe" style="width:100%;height:90%;overflow:auto;" frameborder=0 src=""></iframe>
	</div>
	
	<div id=information1 style='display:none;'>
		<form id='information_page1' name='information_page1'>
			<div class=form>
				<div class="formTitle">申请单明细</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable label5 col2">
					<tr>
						<td><label>单据编号</label> <span id="id"></span></td>
						<td><label>卡片类型</label> <span id="cardType"></span></td>
					</tr>
					<tr>
						<td><label>申&nbsp;请&nbsp;方</label> <span id="location"></span></td>
						<td><label>完成日期</label> <span id="completeDate"></span></td>
					</tr>
					<tr>	
						<td><label>需求数量</label> <span id="amount"></span></td>
						<td><label>申请日期</label> <span id="reqestDate"></span></td>
					</tr>
					<tr>
						<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <span id="status"></span></td>
						<td><label>申请备注</label> <span id="requestComment"></span></td>
					</tr>
					<tr>	
						<td><label>拒绝原因</label> <input type="text" name="description" onblur="checkV(this,'',true)" maxlength="64"/><span class="des">*</span></td>
						<td></td>
					</tr>
				</table>
			</div>
		</form>
		<button type="button" onclick="validate()">拒 绝</button>
		<button type="button" onclick="switchPage('listview')">返 回</button>
	</div>
	<div id=information2 style='display:none;'>
		<form id='information_page2' name='information_page2'>
			<div class=form>
				<div class="formTitle">申请单明细</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable label5 col2">
					<tr>
						<td><label>单据编号</label> <span id="id"></span></td>
						<td><label>卡片类型</label> <span id="cardType"></span></td>
					</tr>
					<tr>
						<td><label>申&nbsp;请&nbsp;方</label> <span id="location"></span></td>
						<td><label>完成日期</label> <span id="completeDate"></span></td>
					</tr>
					<tr>	
						<td><label>需求数量</label> <span id="amount"></span></td>
						<td><label>申请日期</label> <span id="reqestDate"></span></td>
					</tr>
					<tr>
						<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <span id="status"></span></td>
						<td><label>申请备注</label> <span id="requestComment"></span></td>
					</tr>
				</table>
			</div>
		</form>
		<button type="button" onclick="affirm()">批 准</button>
		<button type="button" onclick="switchPage('listview')">返 回</button>
	</div>
</body>
</html>
